package com.src.java.classloader;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class TestClient {

	public static void main(String[] a) throws MalformedURLException, ClassNotFoundException, InstantiationException,
			IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException,
			InvocationTargetException {

		File file = new File("D:\\AmitKumar\\Personal\\PPT\\GPSWorkSpace\\CoreJava\\CoreJava\\jar\\wrapper.jar");

		if (file.exists()) {
			final String FILE_PREFIX = "file:///";
			List<URL> urlList = new ArrayList<URL>();
			urlList.add(new URL(FILE_PREFIX + file.getAbsolutePath()));

			CustomClassLoader classLoader = new CustomClassLoader(urlList);			
			
			Class<?> myclass = classLoader.loadClass("com.src.java.wrappers.WrapperDemo", false);
			Method m = myclass.getMethod("main", String[].class); // get the method you want to call
			String[] args = new String[1];
			m.invoke(null, args); // invoke the method
		} else {
			System.out.println("Jar file not exists...");
		}

	}
}
